<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>新增通知</title>
    <meta name="decorator" content="default"/>
    <link href="${ctxStatic}/static_back/css/public.css" type="text/css" rel="stylesheet">
    <link href="${ctxStatic}/static_back/css/main.css" type="text/css" rel="stylesheet">
</head>

<body>
    <%--标题--%>
    <div class="top-section">
        <input id="btnCancel" class="back-link" type="button" value="&lt;" onclick="history.go(-1)"/>
        <h2>新增通知</h2>
    </div>

    <%--表单主体--%>
    <div class="body-section white-body form-body" >
        <form:form id="inputForm" modelAttribute="airSendMessage" action="${ctx}/air/airSendMessage/save" method="post" >
            <form:hidden path="id"/>
            <sys:message content="${message}"/>

            <div class="form-box" style="width: 600px;">
                <div class="input-div">
                    <span>消息类型</span>
                    <div>
                        <form:select path="type">
                            <form:options items="${fns:getDictList('msg_type')}" itemLabel="label" itemValue="value"
                                          htmlEscape="false"/>
                        </form:select>
                    </div>
                </div>
                <div class="input-div">
                    <span>接收方</span>
                    <div>
                        <form:select path="recevier">
                            <form:options items="${fns:getDictList('msg_receiver')}" itemLabel="label" itemValue="value"
                                          htmlEscape="false"/>
                        </form:select>
                    </div>
                </div>
                <div class="input-div" style="display: none">
                    <span>发送方</span>
                    <div>
                        <form:select path="sender">
                            <form:options items="${fns:getDictList('msg_sender')}" itemLabel="label" itemValue="value"
                                          htmlEscape="false"/>
                        </form:select>
                    </div>
                </div>
                <div class="input-div" style="margin-bottom: 4px;">
                    <span>消息内容</span>
                    <div>
                        <form:textarea path="content" htmlEscape="false" rows="5" />
                        <em>*</em>
                    </div>
                </div>
                <div class="input-div">
                    <div>
                        <input type="checkbox" value="1" name="sendToPhone" id="sendToPhone" />
                        <label for="sendToPhone">推送手机短信</label>
                    </div>
                </div>
            </div>

            <div class="form-bottom">
                <shiro:hasPermission name="air:airSendMessage:edit">
                    <input id="btnSubmit" class="btn btn-blue" type="submit" value="确认发布"/>
                </shiro:hasPermission>
            </div>
        </form:form>
    </div>

    <div id="phoneDiv" class="window-layer window-mini">
        <div class="window-bg"></div>
        <div class="window-main">
            <h3>短信推送</h3>
            <div class="window-body">
                <p>请输入短信推送密码</p>
                <p class="sub-p">
                    输入正确则将该通知以<span>手机短信形式</span>推送给相关人员
                </p>
                <input type="password" id="phonePwd" style="width: 310px;text-align: center"/>
                <em id="phoneErrorMsg" class="error-msg"></em>
            </div>
            <div class="window-bottom">
                <input id="phoneSubmit" type="button" class="btn btn-blue" value="确认推送" />
                <input type="button" class="btn"  value="取 消" onclick="closePhoneDiv()"/>
            </div>
        </div>
    </div>


    <script type="text/javascript">
        $(document).ready(function () {
            $("#name").focus();
            $("#inputForm").validate({
                submitHandler: function (form) {
//                    loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function (error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });

            $("#phoneSubmit").bind("click", function () {
                var result = checkPhonePwd();
                if(result === true){
                    closePhoneDiv();
                    $("#inputForm").submit();
                }
            });
            $("#btnSubmit").bind("click",function () {
                var sendToPhone = $("#sendToPhone").is(":checked");
                if(sendToPhone === true){
                    $("#phoneDiv").css('display', 'block');
                }
                return !sendToPhone;
            })
        });

        function closePhoneDiv() {
            $("#phoneDiv").css('display', 'none');
        }

        function checkPhonePwd() {
            var phonePwd = $.trim($("#phonePwd").val());
            if (phonePwd === "" || typeof phonePwd === "undefined") {
                $("#phoneErrorMsg").html("不能为空！");
                return false;
            }
            if (phonePwd != "12345") {
                $("#phoneErrorMsg").html("推送密码错误！");
                return false;
            }
            $("#phoneErrorMsg").html("");
            return true;
        }
    </script>
</body>

</html>